**************************************************************************************************
*** This do file creates the replication results for 
*** The Impact of the Indian Ocean tsunami on Aceh’s Long-Term Economic Growth (with Martin Heger), 
*** Journal of Development Economics, 141, 2019, 102365, https://doi.org/10.1016/j.jdeveco.2019.06.008
							
**************************************************************************************************
**************************************************************************************************
/* Note: You have to change "local DIR" to the directory you copy the original stata files contained 	*/
/* in the zip file and then run the do file. 
/* You must have Stata version 13 or higher installed													*/
**************************************************************************************************
*/

drop _all
clear matrix
clear mata


***********************************************************************************
local DIR = "d:\Research\Disasters\Heger"  /*change relative path to the directory where the files are located */
cd "`DIR'"
***********************************************************************************




*************************************

* Table 1

*************************************


use "Article for JED (Kecamatans).dta", replace

capture drop flooded_dummy
gen flooded_dummy=0
replace flooded_dummy=1 if pop_flooded_sum>0 & pop_flooded_sum<.

sum lights_mean if flooded_dummy==0 & year==2004
sum lights_mean if flooded_dummy==1 & year==2004




*************************************

* Table 2

*************************************


use "Article for JED (districts).dta", replace


capture dropvars aceh_lead1_0304 aceh_treat1_0608 aceh_treat1_0912
gen aceh_lead1_0304=aceh_lead1_03+aceh_lead1_04
gen aceh_treat1_0608=aceh_treat1_06+aceh_treat1_07+aceh_treat1_08
gen aceh_treat1_0912=aceh_treat1_09+aceh_treat1_10+aceh_treat1_11+aceh_treat1_12


capture dropvars aceh_lead2_0304 aceh_treat2_0608 aceh_treat2_0912
gen aceh_lead2_0304=aceh_lead2_03+aceh_lead2_04
gen aceh_treat2_0608=aceh_treat2_06+aceh_treat2_07+aceh_treat2_08
gen aceh_treat2_0912=aceh_treat2_09+aceh_treat2_10+aceh_treat2_11+aceh_treat2_12


capture dropvars aceh_lead3_0304 aceh_treat3_0608 aceh_treat3_0912
gen aceh_lead3_0304=aceh_lead3_03+aceh_lead3_04
gen aceh_treat3_0608=aceh_treat3_06+aceh_treat3_07+aceh_treat3_08
gen aceh_treat3_0912=aceh_treat3_09+aceh_treat3_10+aceh_treat3_11+aceh_treat3_12



ols_spatial_HAC log_gr aceh_lead3_0304 aceh_treat3_05 aceh_treat3_0608 aceh_treat3_0912 yy* acehthreecc* if tsunami_aceh3!=. , timevar(year) panelvar(region2) lat(latitude) lon(longitude) distcutoff(100) lagcutoff(10)
outreg2 using table2, excel replace
lincom  3*aceh_treat3_0608+ 4*aceh_treat3_0912

ols_spatial_HAC log_gr  aceh_lead2_0304 aceh_treat2_05 aceh_treat2_0608 aceh_treat2_0912  yy* acehtwocc* if tsunami_aceh2!=. , timevar(year) panelvar(region2) lat(latitude) lon(longitude) distcutoff(100) lagcutoff(10)
outreg2 using table2, excel append
lincom  3*aceh_treat2_0608+ 4*aceh_treat2_0912

ols_spatial_HAC log_gr  aceh_lead1_0304 aceh_treat1_05 aceh_treat1_0608 aceh_treat1_0912  yy* acehonecc* if tsunami_aceh1!=. , timevar(year) panelvar(region2) lat(latitude) lon(longitude) distcutoff(100) lagcutoff(10) 
outreg2 using table2, excel append
lincom  3*aceh_treat1_0608+ 4*aceh_treat1_0912


*** compare absolute growth rates before and after tsunami in affected districts
preserve
keep if aceh_lead1==1 | aceh_treat1_0608==1 | aceh_treat1_0912==1
keep log_gr year
capture drop pre_tsunami
gen pre_tsunami=(year<=2004 & year>2000)
capture drop post_tsunami_0608
gen post_tsunami_0608=(year>=2006 & year<=2008)
capture drop post_tsunami_0812
gen post_tsunami_0812=(year>=2008 & year<=2012)
capture drop post_tsunami_0612
gen post_tsunami_0612=(year>=2006 & year<=2012)
sum log_gr if pre_tsunami==1
sum log_gr if post_tsunami_0608==1
sum log_gr if post_tsunami_0812==1
sum log_gr if post_tsunami_0612==1
restore


*************************************

* Table 3

*************************************


use "Article for JED (Kecamatans).dta", replace


tsset id year 

gen log_lights = ln(0.001 + lights_sum)  
gen log_lights_ch = log_lights - l.log_lights



*** Population share flooded 
capture dropvars pop_share_flooded 
gen pop_share_flooded = pop_flooded_sum / pop_sum * 100


capture dropvars  pop_share_flooded_lead0304 pop_share_flooded_treat_05 pop_share_flooded_treat_0608 pop_share_flooded_treat_0912
gen pop_share_flooded_lead0304=pop_share_flooded
replace pop_share_flooded_lead0304=0 if year<2003 | year>2004
gen pop_share_flooded_treat_05=pop_share_flooded
replace pop_share_flooded_treat_05=0 if year!=2005
gen pop_share_flooded_treat_0608=pop_share_flooded
replace pop_share_flooded_treat_0608=0 if year<2006 | year>2008
gen pop_share_flooded_treat_0912=pop_share_flooded
replace pop_share_flooded_treat_0912=0 if year<2009


xtreg log_lights_ch pop_share_flooded_lead0304 pop_share_flooded_treat_05 pop_share_flooded_treat_0608 pop_share_flooded_treat_0912 i.year if gas!=1 & year>=1999, fe robust
outreg2 using table3, excel replace
lincom  3*pop_share_flooded_treat_0608+ 4*pop_share_flooded_treat_0912



*** Area flooded 
capture dropvars  area_share_flooded
gen area_share_flooded = flood_intensity_3


capture dropvars  area_share_flooded_lead0304 area_share_flooded_treat_05 area_share_flooded_treat_0608 area_share_flooded_treat_0912
gen area_share_flooded_lead0304=area_share_flooded
replace area_share_flooded_lead0304=0 if year<2003 | year>2004
gen area_share_flooded_treat_05=area_share_flooded
replace area_share_flooded_treat_05=0 if year!=2005
gen area_share_flooded_treat_0608=area_share_flooded
replace area_share_flooded_treat_0608=0 if year<2006 | year>2008
gen area_share_flooded_treat_0912=area_share_flooded
replace area_share_flooded_treat_0912=0 if year<2009


xtreg log_lights_ch area_share_flooded_lead0304 area_share_flooded_treat_05 area_share_flooded_treat_0608 area_share_flooded_treat_0912 i.year if gas!=1 & year>=1999, fe robust
outreg2 using table3, excel append
lincom  3*area_share_flooded_treat_0608+ 4*area_share_flooded_treat_0912



*************************************

* Table 4

*************************************


use "Article for JED (Kecamatans).dta", replace


*** Change to log lights (transformation a la Mochalopoulos & Lowe)
*** Only look at the latest satelite (since it's starting already in 1999 anyways 

tsset id year 

gen log_lights = ln(0.001 + lights_sum)  
gen log_lights_ch = log_lights - l.log_lights




*** Population share flooded 
capture dropvars pop_share_flooded 
gen pop_share_flooded = pop_flooded_sum / pop_sum * 100



xtile pop_share_flooded_5 = pop_share_flooded if pop_share_flooded!=0, nq(5)


capture dropvars  pop_share_flooded_q1 pop_share_flooded_q2 pop_share_flooded_q3 pop_share_flooded_q4 pop_share_flooded_q5
gen pop_share_flooded_q1=0
replace pop_share_flooded_q1=1 if year>2004 & pop_share_flooded_5==1
gen pop_share_flooded_q2=0
replace pop_share_flooded_q2=1 if year>2004 & pop_share_flooded_5==2
gen pop_share_flooded_q3=0
replace pop_share_flooded_q3=1 if year>2004 & pop_share_flooded_5==3
gen pop_share_flooded_q4=0
replace pop_share_flooded_q4=1 if year>2004 & pop_share_flooded_5==4
gen pop_share_flooded_q5=0
replace pop_share_flooded_q5=1 if year>2004 & pop_share_flooded_5==5

xtreg log_lights_ch pop_share_flooded_q* i.year if gas!=1 & year>=1999, fe robust
outreg2 using table4, excel replace



*** Area flooded 
capture dropvars  area_share_flooded
gen area_share_flooded = flood_intensity_3

xtile area_share_flooded_5 = area_share_flooded if area_share_flooded!=0, nq(5)


capture dropvars  area_share_flooded_q1 area_share_flooded_q2 area_share_flooded_q3 area_share_flooded_q4 area_share_flooded_q5
gen area_share_flooded_q1=0
replace area_share_flooded_q1=1 if year>2004 & area_share_flooded_5==1
gen area_share_flooded_q2=0
replace area_share_flooded_q2=1 if year>2004 & area_share_flooded_5==2
gen area_share_flooded_q3=0
replace area_share_flooded_q3=1 if year>2004 & area_share_flooded_5==3
gen area_share_flooded_q4=0
replace area_share_flooded_q4=1 if year>2004 & area_share_flooded_5==4
gen area_share_flooded_q5=0
replace area_share_flooded_q5=1 if year>2004 & area_share_flooded_5==5

xtreg log_lights_ch area_share_flooded_q* i.year if gas!=1 & year>=1999, fe robust
outreg2 using table4, excel append





*************************************

* Table 5

*************************************

*** NORTH SUMATRA INCLUCDED*** 

use "Article for JED (districts).dta", replace


capture dropvars sumatra_lead1_0304 sumatra_treat1_0608 sumatra_treat1_0912
gen sumatra_lead1_0304=sumatra_lead1_03+sumatra_lead1_04
gen sumatra_treat1_0608=sumatra_treat1_06+sumatra_treat1_07+sumatra_treat1_08
gen sumatra_treat1_0912=sumatra_treat1_09+sumatra_treat1_10+sumatra_treat1_11+sumatra_treat1_12


capture dropvars sumatra_lead2_0304 sumatra_treat2_0608 sumatra_treat2_0912
gen sumatra_lead2_0304=sumatra_lead2_03+sumatra_lead2_04
gen sumatra_treat2_0608=sumatra_treat2_06+sumatra_treat2_07+sumatra_treat2_08
gen sumatra_treat2_0912=sumatra_treat2_09+sumatra_treat2_10+sumatra_treat2_11+sumatra_treat2_12


capture dropvars sumatra_lead3_0304 sumatra_treat3_0608 sumatra_treat3_0912
gen sumatra_lead3_0304=sumatra_lead3_03+sumatra_lead3_04
gen sumatra_treat3_0608=sumatra_treat3_06+sumatra_treat3_07+sumatra_treat3_08
gen sumatra_treat3_0912=sumatra_treat3_09+sumatra_treat3_10+sumatra_treat3_11+sumatra_treat3_12


* COMBINED PERIODS MODEL


ols_spatial_HAC log_gr sumatra_lead3_0304 sumatra_treat3_05 sumatra_treat3_0608 sumatra_treat3_0912 yy* sumatrathreecc* if tsunami_sumatra3!=. , timevar(year) panelvar(region2) lat(latitude) lon(longitude) distcutoff(100) lagcutoff(10)
outreg2 using table5, excel replace
lincom  3*sumatra_treat3_0608+ 4*sumatra_treat3_0912

ols_spatial_HAC log_gr  sumatra_lead2_0304 sumatra_treat2_05 sumatra_treat2_0608 sumatra_treat2_0912  yy* sumatratwocc* if tsunami_sumatra2!=. , timevar(year) panelvar(region2) lat(latitude) lon(longitude) distcutoff(100) lagcutoff(10)
outreg2 using table5, excel append
lincom  3*sumatra_treat2_0608+ 4*sumatra_treat2_0912

ols_spatial_HAC log_gr  sumatra_lead1_0304 sumatra_treat1_05 sumatra_treat1_0608 sumatra_treat1_0912  yy* sumatraonecc* if tsunami_sumatra1!=. , timevar(year) panelvar(region2) lat(latitude) lon(longitude) distcutoff(100) lagcutoff(10) 
outreg2 using table5, excel append
lincom  3*sumatra_treat1_0608+ 4*sumatra_treat1_0912




*************************************

* Table 6

*************************************

*** COASTAL DISTRICTS ONLY*** 

use "Article for JED (districts).dta", replace


preserve

drop if year==.
*** because of growth rates taken, the 1999 obs disappears, as the growth rate btw 1999 and 2000 is recoreded in the 2000 row.
drop if year==1999

capture dropvars noncoastal_aceh
rename noncoastal noncoastal_aceh
gen noncoastal =.
replace noncoastal = 1 if  region == "Aceh Tengah"
replace noncoastal = 1 if  region == "Aceh Tenggara"
replace noncoastal = 1 if  region == "Batanghari"
replace noncoastal = 1 if  region == "Bungo"
replace noncoastal = 1 if  region == "Dairi"
replace noncoastal = 1 if  region == "Gayo Lues"
replace noncoastal = 1 if  region == "Indragiri Hulu"
replace noncoastal = 1 if  region == "Jambi"
replace noncoastal = 1 if  region == "Kampar"
replace noncoastal = 1 if  region == "Kerinci"
replace noncoastal = 1 if  region == "Kuantan Singingi"
replace noncoastal = 1 if  region == "Lahat"
replace noncoastal = 1 if  region == "Lampung Utara"
replace noncoastal = 1 if  region == "Limapuluh Koto"
replace noncoastal = 1 if  region == "Merangin"
replace noncoastal = 1 if  region == "Muaro Jambi"
replace noncoastal = 1 if  region == "Musi Banyuasin"
replace noncoastal = 1 if  region == "Ogan Komering Ulu"
replace noncoastal = 1 if  region == "Padang Sidempuan"
replace noncoastal = 1 if  region == "Pagar Alam"
replace noncoastal = 1 if  region == "Payakumbuh"
replace noncoastal = 1 if  region == "Pekan Baru"
replace noncoastal = 1 if  region == "Pematang Siantar"
replace noncoastal = 1 if  region == "Prabumulih"
replace noncoastal = 1 if  region == "Rokan Hulu"
replace noncoastal = 1 if  region == "Sarolangun"
replace noncoastal = 1 if  region == "Sawahlunto"
replace noncoastal = 1 if  region == "Simalungun"
replace noncoastal = 1 if  region == "Solok"
replace noncoastal = 1 if  region == "Tebo"
replace noncoastal = 1 if  region == "Toba Samosir"
replace noncoastal = 1 if  region == "Way Kanan"



*** ONLY COASTAL
drop if noncoastal==1


* drop if tsunami_sumatra==.
drop if island !=6

capture dropvars yy*
quietly tab year, gen(yy)

capture dropvars acehonecc* acehtwocc* acehthreecc* pp* rr*
quietly tab region if tsunami_aceh1!=., gen(acehonecc) 
quietly tab region if tsunami_aceh2!=., gen(acehtwocc) 
quietly tab region if tsunami_aceh3!=., gen(acehthreecc) 


quietly tab prov, gen(pp)
quietly tab region_year, gen(rr)

*** avoid dummy trap
capture dropvars ybench pbench rbench
rename yy1 ybench
rename pp9 pbench

rename rr1 rbench


capture dropvars aceh_lead1_0304 aceh_treat1_0608 aceh_treat1_0912
gen aceh_lead1_0304=aceh_lead1_03+aceh_lead1_04
gen aceh_treat1_0608=aceh_treat1_06+aceh_treat1_07+aceh_treat1_08
gen aceh_treat1_0912=aceh_treat1_09+aceh_treat1_10+aceh_treat1_11+aceh_treat1_12


capture dropvars aceh_lead2_0304 aceh_treat2_0608 aceh_treat2_0912
gen aceh_lead2_0304=aceh_lead2_03+aceh_lead2_04
gen aceh_treat2_0608=aceh_treat2_06+aceh_treat2_07+aceh_treat2_08
gen aceh_treat2_0912=aceh_treat2_09+aceh_treat2_10+aceh_treat2_11+aceh_treat2_12


capture dropvars aceh_lead3_0304 aceh_treat3_0608 aceh_treat3_0912
gen aceh_lead3_0304=aceh_lead3_03+aceh_lead3_04
gen aceh_treat3_0608=aceh_treat3_06+aceh_treat3_07+aceh_treat3_08
gen aceh_treat3_0912=aceh_treat3_09+aceh_treat3_10+aceh_treat3_11+aceh_treat3_12



ols_spatial_HAC log_gr aceh_lead3_0304 aceh_treat3_05 aceh_treat3_0608 aceh_treat3_0912 yy* acehthreecc* if tsunami_aceh3!=. , timevar(year) panelvar(region2) lat(latitude) lon(longitude) distcutoff(100) lagcutoff(10)
outreg2 using table6, excel replace
lincom  3*aceh_treat3_0608+ 4*aceh_treat3_0912

ols_spatial_HAC log_gr  aceh_lead2_0304 aceh_treat2_05 aceh_treat2_0608 aceh_treat2_0912  yy* acehtwocc* if tsunami_aceh2!=. , timevar(year) panelvar(region2) lat(latitude) lon(longitude) distcutoff(100) lagcutoff(10)
outreg2 using table6, excel append
lincom  3*aceh_treat2_0608+ 4*aceh_treat2_0912

ols_spatial_HAC log_gr  aceh_lead1_0304 aceh_treat1_05 aceh_treat1_0608 aceh_treat1_0912  yy* acehonecc* if tsunami_aceh1!=. , timevar(year) panelvar(region2) lat(latitude) lon(longitude) distcutoff(100) lagcutoff(10) 
outreg2 using table6, excel append
lincom  3*aceh_treat1_0608+ 4*aceh_treat1_0912

restore



*************************************

* Table 7

*************************************

*** CITIES VERSUS RURAL DISTRICTS *** 

use "Article for JED (districts).dta", replace


preserve

drop if year==.
*** because of growth rates taken, the 1999 obs disappears, as the growth rate btw 1999 and 2000 is recoreded in the 2000 row.
drop if year==1999

*** Generate time and city dummies, bc the ols_spatial_HAC comment doesn't allow for i.region or i.year operators

drop if district_type=="Kab"


capture dropvars yy*
quietly tab year, gen(yy)

capture dropvars acehonecc* acehtwocc* acehthreecc* pp* rr*
quietly tab region if tsunami_aceh1!=., gen(acehonecc) 
quietly tab region if tsunami_aceh2!=., gen(acehtwocc) 
quietly tab region if tsunami_aceh3!=., gen(acehthreecc) 


quietly tab prov, gen(pp)
quietly tab region_year, gen(rr)

*** avoid dummy trap
capture dropvars ybench pbench rbench
rename yy1 ybench
rename pp9 pbench

rename rr1 rbench


capture dropvars aceh_lead1_0304 aceh_treat1_0608 aceh_treat1_0912
gen aceh_lead1_0304=aceh_lead1_03+aceh_lead1_04
gen aceh_treat1_0608=aceh_treat1_06+aceh_treat1_07+aceh_treat1_08
gen aceh_treat1_0912=aceh_treat1_09+aceh_treat1_10+aceh_treat1_11+aceh_treat1_12


capture dropvars aceh_lead2_0304 aceh_treat2_0608 aceh_treat2_0912
gen aceh_lead2_0304=aceh_lead2_03+aceh_lead2_04
gen aceh_treat2_0608=aceh_treat2_06+aceh_treat2_07+aceh_treat2_08
gen aceh_treat2_0912=aceh_treat2_09+aceh_treat2_10+aceh_treat2_11+aceh_treat2_12


capture dropvars aceh_lead3_0304 aceh_treat3_0608 aceh_treat3_0912
gen aceh_lead3_0304=aceh_lead3_03+aceh_lead3_04
gen aceh_treat3_0608=aceh_treat3_06+aceh_treat3_07+aceh_treat3_08
gen aceh_treat3_0912=aceh_treat3_09+aceh_treat3_10+aceh_treat3_11+aceh_treat3_12



ols_spatial_HAC log_gr aceh_lead3_0304 aceh_treat3_05 aceh_treat3_0608 aceh_treat3_0912 yy* acehthreecc* if tsunami_aceh3!=. , timevar(year) panelvar(region2) lat(latitude) lon(longitude) distcutoff(100) lagcutoff(10)
outreg2 using table7, excel replace
lincom  3*aceh_treat3_0608+ 4*aceh_treat3_0912

ols_spatial_HAC log_gr  aceh_lead2_0304 aceh_treat2_05 aceh_treat2_0608 aceh_treat2_0912  yy* acehtwocc* if tsunami_aceh2!=. , timevar(year) panelvar(region2) lat(latitude) lon(longitude) distcutoff(100) lagcutoff(10)
outreg2 using table7, excel append
lincom  3*aceh_treat2_0608+ 4*aceh_treat2_0912


ols_spatial_HAC log_gr  aceh_lead1_0304 aceh_treat1_05 aceh_treat1_0608 aceh_treat1_0912  yy* acehonecc* if tsunami_aceh1!=. , timevar(year) panelvar(region2) lat(latitude) lon(longitude) distcutoff(100) lagcutoff(10) 
outreg2 using table7, excel append
lincom  3*aceh_treat1_0608+ 4*aceh_treat1_0912

restore


/// RURAL AREAS

use "Article for JED (districts).dta", replace

preserve

drop if year==.
*** because of growth rates taken, the 1999 obs disappears, as the growth rate btw 1999 and 2000 is recoreded in the 2000 row.
drop if year==1999

*** Generate time and city dummies, bc the ols_spatial_HAC comment doesn't allow for i.region or i.year operators

drop if district_type=="Kota"


capture dropvars yy*
quietly tab year, gen(yy)

capture dropvars acehonecc* acehtwocc* acehthreecc* pp* rr*
quietly tab region if tsunami_aceh1!=., gen(acehonecc) 
quietly tab region if tsunami_aceh2!=., gen(acehtwocc) 
quietly tab region if tsunami_aceh3!=., gen(acehthreecc) 


quietly tab prov, gen(pp)
quietly tab region_year, gen(rr)

*** avoid dummy trap
capture dropvars ybench pbench rbench
rename yy1 ybench
rename pp9 pbench

rename rr1 rbench



capture dropvars aceh_lead1_0304 aceh_treat1_0608 aceh_treat1_0912
gen aceh_lead1_0304=aceh_lead1_03+aceh_lead1_04
gen aceh_treat1_0608=aceh_treat1_06+aceh_treat1_07+aceh_treat1_08
gen aceh_treat1_0912=aceh_treat1_09+aceh_treat1_10+aceh_treat1_11+aceh_treat1_12


capture dropvars aceh_lead2_0304 aceh_treat2_0608 aceh_treat2_0912
gen aceh_lead2_0304=aceh_lead2_03+aceh_lead2_04
gen aceh_treat2_0608=aceh_treat2_06+aceh_treat2_07+aceh_treat2_08
gen aceh_treat2_0912=aceh_treat2_09+aceh_treat2_10+aceh_treat2_11+aceh_treat2_12


capture dropvars aceh_lead3_0304 aceh_treat3_0608 aceh_treat3_0912
gen aceh_lead3_0304=aceh_lead3_03+aceh_lead3_04
gen aceh_treat3_0608=aceh_treat3_06+aceh_treat3_07+aceh_treat3_08
gen aceh_treat3_0912=aceh_treat3_09+aceh_treat3_10+aceh_treat3_11+aceh_treat3_12



ols_spatial_HAC log_gr aceh_lead3_0304 aceh_treat3_05 aceh_treat3_0608 aceh_treat3_0912 yy* acehthreecc* if tsunami_aceh3!=. , timevar(year) panelvar(region2) lat(latitude) lon(longitude) distcutoff(100) lagcutoff(10)
outreg2 using table7, excel append
lincom  3*aceh_treat3_0608+ 4*aceh_treat3_0912

ols_spatial_HAC log_gr  aceh_lead2_0304 aceh_treat2_05 aceh_treat2_0608 aceh_treat2_0912  yy* acehtwocc* if tsunami_aceh2!=. , timevar(year) panelvar(region2) lat(latitude) lon(longitude) distcutoff(100) lagcutoff(10)
outreg2 using table7, excel append
lincom  3*aceh_treat2_0608+ 4*aceh_treat2_0912


ols_spatial_HAC log_gr  aceh_lead1_0304 aceh_treat1_05 aceh_treat1_0608 aceh_treat1_0912  yy* acehonecc* if tsunami_aceh1!=. , timevar(year) panelvar(region2) lat(latitude) lon(longitude) distcutoff(100) lagcutoff(10) 
outreg2 using table7, excel append
lincom  3*aceh_treat1_0608+ 4*aceh_treat1_0912

restore




*************************************

* Table 8

*************************************

*** GDP PER CAPITA instead of GDP growth *** 

use "Article for JED (districts).dta", replace


preserve

* Drop problematic Subulussalam GDP data
replace log_cap_gr=. if region=="Subulussalam" & (year==2003 | year==2004 | year==2005 | year==2006)



capture dropvars aceh_lead1_0304 aceh_treat1_0608 aceh_treat1_0912
gen aceh_lead1_0304=aceh_lead1_03+aceh_lead1_04
gen aceh_treat1_0608=aceh_treat1_06+aceh_treat1_07+aceh_treat1_08
gen aceh_treat1_0912=aceh_treat1_09+aceh_treat1_10+aceh_treat1_11+aceh_treat1_12


capture dropvars aceh_lead2_0304 aceh_treat2_0608 aceh_treat2_0912
gen aceh_lead2_0304=aceh_lead2_03+aceh_lead2_04
gen aceh_treat2_0608=aceh_treat2_06+aceh_treat2_07+aceh_treat2_08
gen aceh_treat2_0912=aceh_treat2_09+aceh_treat2_10+aceh_treat2_11+aceh_treat2_12


capture dropvars aceh_lead3_0304 aceh_treat3_0608 aceh_treat3_0912
gen aceh_lead3_0304=aceh_lead3_03+aceh_lead3_04
gen aceh_treat3_0608=aceh_treat3_06+aceh_treat3_07+aceh_treat3_08
gen aceh_treat3_0912=aceh_treat3_09+aceh_treat3_10+aceh_treat3_11+aceh_treat3_12



ols_spatial_HAC log_cap_gr aceh_lead3_0304 aceh_treat3_05 aceh_treat3_0608 aceh_treat3_0912 yy* acehthreecc* if tsunami_aceh3!=. , timevar(year) panelvar(region2) lat(latitude) lon(longitude) distcutoff(100) lagcutoff(10)
outreg2 using table8, excel replace
lincom  3*aceh_treat3_0608+ 4*aceh_treat3_0912

ols_spatial_HAC log_cap_gr  aceh_lead2_0304 aceh_treat2_05 aceh_treat2_0608 aceh_treat2_0912  yy* acehtwocc* if tsunami_aceh2!=. , timevar(year) panelvar(region2) lat(latitude) lon(longitude) distcutoff(100) lagcutoff(10)
outreg2 using table8, excel append
lincom  3*aceh_treat2_0608+ 4*aceh_treat2_0912

ols_spatial_HAC log_cap_gr  aceh_lead1_0304 aceh_treat1_05 aceh_treat1_0608 aceh_treat1_0912  yy* acehonecc* if tsunami_aceh1!=. , timevar(year) panelvar(region2) lat(latitude) lon(longitude) distcutoff(100) lagcutoff(10) 
outreg2 using table8, excel append
lincom  3*aceh_treat1_0608+ 4*aceh_treat1_0912

restore




*************************************

* Table 9

*************************************

*** Placebo test on neighbouring districts to test for spill-over effects from treated units 

use "Article for JED (districts).dta", replace


capture dropvars spillover

gen spillover = .
replace spillover = 1 if region =="Aceh Selatan"
replace spillover = 1 if region =="Aceh Singkil"
replace spillover = 1 if region =="Aceh Tengah"
replace spillover = 1 if region =="Aceh Tenggara"
replace spillover = 1 if region =="Aceh Utara"
replace spillover = 1 if region =="Gayo Lues"
replace spillover = 1 if region =="Lhokseumawe"
replace spillover = 1 if region =="Mandailing Natal"
replace spillover = 1 if region =="Tapanuli Selatan"
replace spillover = 1 if region =="Tapanuli Tengah"

replace spillover = 2 if region =="Aceh Tamiang"
replace spillover = 2 if region =="Aceh Timur"
replace spillover = 2 if region =="Langsa"
replace spillover = 2 if region =="Asahan"
replace spillover = 2 if region =="Binjai"
replace spillover = 2 if region =="Dairi"
replace spillover = 2 if region =="Deli Serdang"
*** change "Karo" as it was spelled in the shape file to "Tanah Karo", as it was spelled in the INDO DAPOER data. 
replace spillover = 2 if region =="Tanah Karo"
replace spillover = 2 if region =="Labuhan Batu"
replace spillover = 2 if region =="Langkat"
replace spillover = 2 if region =="Medan"
replace spillover = 2 if region =="Padang Sidempuan"
replace spillover = 2 if region =="Pematang Siantar"
replace spillover = 2 if region =="Simalungun"
replace spillover = 2 if region =="Tanjung Balai"
replace spillover = 2 if region =="Tapanuli Utara"
replace spillover = 2 if region =="Tebing Tinggi"
replace spillover = 2 if region =="Toba Samosir"

replace spillover = 3 if tsunami_sumatra == 2

replace spillover = 0 if spillover ==.

lab var spillover "Neighbor-districts (directly adjacent) to stricken districts"
la define spillover 1 "Neighbors of stricken districts" 2 "Non-neighbors of stricken districts" 3 "Tsunami stricken" 0 "Rest of Sumatra"
la val spillover spillover 


drop if spillover==3


drop if year==.
*** because of growth rates taken, the 1999 obs disappears, as the growth rate btw 1999 and 2000 is recoreded in the 2000 row.
drop if year==1999

*** Generate time and city dummies, bc the ols_spatial_HAC comment doesn't allow for i.region or i.year operators

***** TURN NORTH SUMATRA ON & OFF ******
drop if tsunami_sumatra==.
drop if island !=6


capture dropvars yy* acehonecc* acehtwocc* acehthreecc* sumatraonecc* sumatratwocc* sumatrathreecc*
quietly tab year, gen(yy)
*** I need to create a different country dummy for each country cluster
quietly tab region if tsunami_aceh1!=., gen(acehonecc) 
quietly tab region if tsunami_aceh2!=., gen(acehtwocc) 
quietly tab region if tsunami_aceh3!=., gen(acehthreecc) 

*** I also need to create a different country dummy for the larger sample that includes the North Sumatra province also
quietly tab region if tsunami_sumatra1!=., gen(sumatraonecc) 
quietly tab region if tsunami_sumatra2!=., gen(sumatratwocc) 
quietly tab region if tsunami_sumatra3!=., gen(sumatrathreecc) 

quietly tab prov, gen(pp)
quietly tab region_year, gen(rr)

*** avoid dummy trap
rename yy1 ybench
rename pp9 pbench
* rename onecc1 onecbench ***NOTE: Variable does not exist
* rename twocc1 twocbench ***NOTE: Variable does not exist
* rename threecc1 threecbench ***NOTE: Variable does not exist
rename rr1 rbench



* Drop problematic Subulussalam GDP data
replace log_gr=. if region=="Subulussalam" & (year==2003 | year==2004 | year==2005 | year==2006)




replace sumatra_lead1_03=1 if spillover==1 & year==2003
replace sumatra_lead1_04=1 if spillover==1 & year==2004
replace sumatra_treat1_05=1 if spillover==1 & year==2005
replace sumatra_treat1_06=1 if spillover==1 & year==2006
replace sumatra_treat1_07=1 if spillover==1 & year==2007
replace sumatra_treat1_08=1 if spillover==1 & year==2008
replace sumatra_treat1_09=1 if spillover==1 & year==2009
replace sumatra_treat1_10=1 if spillover==1 & year==2010
replace sumatra_treat1_11=1 if spillover==1 & year==2011
replace sumatra_treat1_12=1 if spillover==1 & year==2012


capture dropvars sumatra_lead1_0304 sumatra_treat1_0608 sumatra_treat1_0912
gen sumatra_lead1_0304=sumatra_lead1_03+sumatra_lead1_04
gen sumatra_treat1_0608=sumatra_treat1_06+sumatra_treat1_07+sumatra_treat1_08
gen sumatra_treat1_0912=sumatra_treat1_09+sumatra_treat1_10+sumatra_treat1_11+sumatra_treat1_12


replace sumatra_lead3_03=1 if spillover==1 & year==2003
replace sumatra_lead3_04=1 if spillover==1 & year==2004
replace sumatra_treat3_05=1 if spillover==1 & year==2005
replace sumatra_treat3_06=1 if spillover==1 & year==2006
replace sumatra_treat3_07=1 if spillover==1 & year==2007
replace sumatra_treat3_08=1 if spillover==1 & year==2008
replace sumatra_treat3_09=1 if spillover==1 & year==2009
replace sumatra_treat3_10=1 if spillover==1 & year==2010
replace sumatra_treat3_11=1 if spillover==1 & year==2011
replace sumatra_treat3_12=1 if spillover==1 & year==2012


capture dropvars sumatra_lead3_0304 sumatra_treat3_0608 sumatra_treat3_0912
gen sumatra_lead3_0304=sumatra_lead3_03+sumatra_lead3_04
gen sumatra_treat3_0608=sumatra_treat3_06+sumatra_treat3_07+sumatra_treat3_08
gen sumatra_treat3_0912=sumatra_treat3_09+sumatra_treat3_10+sumatra_treat3_11+sumatra_treat3_12

sum sumatra_lead3_0304 sumatra_treat3_0608 sumatra_treat3_0912




ols_spatial_HAC log_gr  sumatra_lead3_0304 sumatra_treat3_05 sumatra_treat3_0608 sumatra_treat3_0912  yy* sumatrathreecc* if tsunami_sumatra3!=. , timevar(year) panelvar(region2) lat(latitude) lon(longitude) distcutoff(100) lagcutoff(10) 
outreg2 using table9, excel replace
lincom  3*sumatra_treat3_0608+ 4*sumatra_treat3_0912

ols_spatial_HAC log_gr  sumatra_lead1_0304 sumatra_treat1_05 sumatra_treat1_0608 sumatra_treat1_0912  yy* sumatraonecc* if tsunami_sumatra1!=. , timevar(year) panelvar(region2) lat(latitude) lon(longitude) distcutoff(100) lagcutoff(10) 
outreg2 using table9, excel append
lincom  3*sumatra_treat1_0608+ 4*sumatra_treat1_0912






*********************************************************	 
********************** SYNTH CONTROL*********************
*********************************************************


use "Article for JED (districts for synthetic control).dta", replace

preserve

* replace the value of Bandah Aceh with the average value of the 10 Tsunami stricken districts of Aceh 
bysort year: egen gdp_aceh = mean(gdp) if tsunami_aceh==2 
bysort year: egen prim_aceh = mean(primary) if tsunami_aceh==2 
bysort year: egen secondary_aceh = mean(secondary) if tsunami_aceh==2 
bysort year: egen tertiary_aceh = mean(tertiary) if tsunami_aceh==2 

bysort year: egen tert_aceh = mean(tert_gdp) if tsunami_aceh==2 
bysort year: egen sec_aceh = mean(sec_gdp) if tsunami_aceh==2 
bysort year: egen agri_aceh = mean(agri_gdp) if tsunami_aceh==2 
bysort year: egen manuf_aceh = mean(manuf_gdp) if tsunami_aceh==2 
bysort year: egen constr_aceh = mean(constr_gdp) if tsunami_aceh==2 
bysort year: egen utilities_aceh = mean(utilities_gdp) if tsunami_aceh==2 

drop if tsunami_aceh==2 & region!="Banda Aceh"

replace gdp = gdp_aceh if region=="Banda Aceh"

replace primary = prim_aceh if region=="Banda Aceh"
replace secondary = secondary_aceh if region=="Banda Aceh"
replace tertiary = tertiary_aceh if region=="Banda Aceh"

replace tert_gdp = tert_aceh if region=="Banda Aceh"
replace sec_gdp = sec_aceh if region=="Banda Aceh"
replace agri_gdp = agri_aceh if region=="Banda Aceh"
replace manuf_gdp = manuf_aceh if region=="Banda Aceh"
replace constr_gdp = constr_aceh if region=="Banda Aceh"
replace utilities_gdp = utilities_aceh if region=="Banda Aceh"

* ID for Tsunami affected Aceh districts is 22
list id if region=="Banda Aceh, Kota"

drop if tsunami_aceh==.
*** compare only with the 72 non-affected districts 
drop if tsunami_aceh == 1

synth gdp  /// 
			gdp(1999) gdp(2000) gdp(2001) gdp(2002) gdp(2003)  //// 
	         agri_gdp(2003) manuf_gdp constr_gdp  ///
	         , trunit(22) trperiod(2004) keep(gap_district, replace) fig 
		 


restore
